package com.wc.AlgoOJ_train.train2_DP训练.c3.DP0106;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/13 0:42
 * @description 分组背包
 * http://43.138.190.70:8888/p/DP0106
 */
public class Main {
    static int maxN = 1000 + 7;
    // arr[i][j][i] 表示第i组第j个的w v
    static int[][][] arr = new int[maxN][maxN][2];
    // nums[i] 表示第i组的个数
    static int[] nums = new int[maxN];
    // 组别，方便遍历
    static int[] groups = new int[maxN];
    static int groupLen = 0;
    static int[] dp = new int[maxN];
    static int n, m;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int a, v, w;
            a = sc.nextInt();
            w = sc.nextInt();
            v = sc.nextInt();
            if (nums[a] == 0) {
                groups[++groupLen] = a;
            }
            ++nums[a];
            arr[a][nums[a]][0] = w;
            arr[a][nums[a]][1] = v;
        }
        for (int i = 1; i <= groupLen; i++) {
            int group = groups[i];
            // 多重背包的，多重背包不是可以选多个，这个是只能选一个或者不选，朴素的多重背包
            for (int j = m; j >= 0; j--) {
                for (int k = 1; k <= nums[group]; k++) {
                    if (j >= arr[group][k][0]) {
                        dp[j] = Math.max(dp[j], dp[j - arr[group][k][0]] + arr[group][k][1]);
                    }
                }
            }
        }
        out.println(dp[m]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
